<%@ page import="java.sql.*, javax.sql.*, javax.naming.*" %>
<%@page import="support.*, java.util.*" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <%
    // get studentid from request
    int studentid = Integer.parseInt(request.getParameter("studentid"));
    
    // prints out all previous reviews
     // Connect to ConnectionPool
    Connection conn = null;
    try{
        Context initCtx = new InitialContext();
        DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/CS135");
        conn = ds.getConnection();
    }finally{
    }
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("SELECT r2.username, r1.grade, r1.content, r1.graded FROM review r1, reviewer r2 WHERE r1.pid =" + studentid + "AND r1.reviewerid = r2.reviewerid");

    out.print("<table border=1 width=300>");
    out.print("<tr><td>Reviewer</td><td>Grade</td><td>Comment</td></tr>");
    while(rset.next()){
        if(rset.getInt("graded") == 1){
            out.print("<tr>");
            out.print("<td>"+rset.getString("username")+"</td><td>" + rset.getInt("grade")+"</td><td>" + rset.getString("content")+"</td>");
            out.print("</tr>");
        }
    }
    out.print("</table>");
    
    // prints out hide button
    out.print("<input type='button' value='Hide Application' onclick=\"hideApp('" + studentid +  "');\">");
    %>
</body>
</html>